package com.example.treasure_back.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.treasure_back.entity.MsgEntity;
import com.example.treasure_back.service.OrderService;
import com.example.treasure_back.shiroEntity.auth.AuthUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/treasure/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/insert")
    private MsgEntity insertOrder(@AuthUser String email, @RequestBody JSONObject jsonObject){
        Integer id = jsonObject.getInteger("id");
        String province = jsonObject.getString("province");
        String city = jsonObject.getString("city");
        String addr = jsonObject.getString("addr");
        String name = jsonObject.getString("name");
        String phone = jsonObject.getString("phone");
        orderService.insertOrder(email,province,city,addr,name,phone,id);
        return new MsgEntity("SUCCESS","200","插入成功");
    }
}
